<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|Microsoft YaHei:300,300italic,400,400italic,700,700italic|Microsoft YaHei:300,300italic,400,400italic,700,700italic|Microsoft YaHei:300,300italic,400,400italic,700,700italic|Inziu Iosevka Slab SC:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="Daily09:  UFLDL Tutorial10: Softmax Regression11: 卷积神经网络 in Wiki https://cs231n.github.io/convolutional-networks/ https://zhuanlan.zhihu.com/p/22038289 卷积神经网络工作原理直观的解释？ http://scs.ryerson.ca/~aharley/">
<meta property="og:type" content="article">
<meta property="og:title" content="2017 09 01">
<meta property="og:url" content="http://idmk.oschina.io/2017/09/09/2017-09-01/index.html">
<meta property="og:site_name" content="苦舟">
<meta property="og:description" content="Daily09:  UFLDL Tutorial10: Softmax Regression11: 卷积神经网络 in Wiki https://cs231n.github.io/convolutional-networks/ https://zhuanlan.zhihu.com/p/22038289 卷积神经网络工作原理直观的解释？ http://scs.ryerson.ca/~aharley/">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://idmk.oschina.io/2017/09/09/2017-09-01/markdown-img-paste-20170911100715418.png">
<meta property="og:image" content="http://idmk.oschina.io/2017/09/09/2017-09-01/markdown-img-paste-20170911111812281.png">
<meta property="og:image" content="http://idmk.oschina.io/2017/09/09/2017-09-01/markdown-img-paste-20170911111826987.png">
<meta property="og:image" content="http://idmk.oschina.io/2017/09/09/2017-09-01/markdown-img-paste-20170911112030158.png">
<meta property="og:image" content="http://idmk.oschina.io/2017/09/09/2017-09-01/markdown-img-paste-20170912152055485.png">
<meta property="og:updated_time" content="2017-09-12T14:46:20.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="2017 09 01">
<meta name="twitter:description" content="Daily09:  UFLDL Tutorial10: Softmax Regression11: 卷积神经网络 in Wiki https://cs231n.github.io/convolutional-networks/ https://zhuanlan.zhihu.com/p/22038289 卷积神经网络工作原理直观的解释？ http://scs.ryerson.ca/~aharley/">
<meta name="twitter:image" content="http://idmk.oschina.io/2017/09/09/2017-09-01/markdown-img-paste-20170911100715418.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    sidebar: {"position":"left","display":"hide","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://idmk.oschina.io/2017/09/09/2017-09-01/"/>





  <title>2017 09 01 | 苦舟</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苦舟</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">学海无涯，吾将上下求索。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://idmk.oschina.io/2017/09/09/2017-09-01/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="东木金">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苦舟">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">2017 09 01</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-09T22:46:20+08:00">
                2017-09-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="Daily"><a href="#Daily" class="headerlink" title="Daily"></a>Daily</h2><p>09:</p>
<ul>
<li>UFLDL Tutorial<br>10:</li>
<li>Softmax Regression<br>11:</li>
<li>卷积神经网络 in Wiki</li>
<li><a href="https://cs231n.github.io/convolutional-networks/" target="_blank" rel="external">https://cs231n.github.io/convolutional-networks/</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/22038289" target="_blank" rel="external">https://zhuanlan.zhihu.com/p/22038289</a></li>
<li><a href="https://www.zhihu.com/question/39022858" target="_blank" rel="external">卷积神经网络工作原理直观的解释？</a></li>
<li><a href="http://scs.ryerson.ca/~aharley/vis/conv/" target="_blank" rel="external">http://scs.ryerson.ca/~aharley/vis/conv/</a></li>
<li><a href="https://m.huxiu.com/article/138857/1.html" target="_blank" rel="external">https://m.huxiu.com/article/138857/1.html</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/23080129" target="_blank" rel="external">Deep Learning Papers Reading Roadmap</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/22339097" target="_blank" rel="external">CS231n 课程翻译系列</a></li>
<li><a href="https://www.zhihu.com/question/30888762" target="_blank" rel="external">如何理解卷积神经网络中的卷积？</a></li>
<li><a href="https://ujjwalkarn.me/2016/08/11/intuitive-explanation-convnets/" target="_blank" rel="external">An Intuitive Explanation of Convolutional</a></li>
<li><a href="https://jizhi.im/blog/post/intuitive_explanation_cnn" target="_blank" rel="external">神经网络的直观解释</a></li>
<li><a href="Autoencoders/">Autoencoders</a></li>
<li>tensorflow 一个最简单的神经网络</li>
<li><a href="https://blog.keras.io/building-autoencoders-in-keras.html" target="_blank" rel="external">Building Autoencoders in Keras</a></li>
<li><a href="https://blog.keras.io/index.html" target="_blank" rel="external">The future of deep learning</a> onenote</li>
<li><a href="////">多层感知机简介 -tensorflow 实战</a><br>12:</li>
<li><a href="/2017/09/12/tf-in-action-google/">TensorFlow 实战 Google 深度学习框架</a></li>
<li><a href="http://deeplearning.stanford.edu/wiki/index.php/%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C" target="_blank" rel="external">神经网络 -OneNote</a></li>
<li><a href="http://deeplearning.stanford.edu/wiki/index.php/%E5%8F%AF%E8%A7%86%E5%8C%96%E8%87%AA%E7%BC%96%E7%A0%81%E5%99%A8%E8%AE%AD%E7%BB%83%E7%BB%93%E6%9E%9C" target="_blank" rel="external">可视化自编码器之隐藏单元对怎样的图像有最大的激励（实现简单特征检测）</a> OneNote<br>13:</li>
<li>tf.estimator (E:/codehose/tensorflow/estimator_demo.py)</li>
<li>estimator_custom_model_deme.py (E:/codehose/tensorflow/estimator_custom_model_deme.py)<br>14:</li>
<li>A Survey of Automated Journalism<br>15:</li>
<li>Numpy<br>16:</li>
<li>Numpy Reference</li>
<li>SciPy Tutorial</li>
<li>Data Visualization</li>
<li>Data Statistics</li>
<li><a href="http://www.scipy-lectures.org/intro/numpy/exercises.html#data-statistics" target="_blank" rel="external">Crude integral approximations</a></li>
<li><a href="http://www.scipy-lectures.org/intro/numpy/exercises.html#data-statistics" target="_blank" rel="external">Markov chain</a></li>
<li>Plotting Of Matplotlib<br>20:</li>
<li>Deep MNIST for Experts</li>
<li>A very simple MNIST classifier</li>
<li>Build a Multilayer Convolutional Network<br>22:</li>
<li>Keras Notes<br>23:</li>
<li><a href="http://www.datasciencebytes.com/bytes/2015/12/18/using-jupyter-notebooks-securely-on-remote-linux-machines/" target="_blank" rel="external">Using Jupyter notebooks securely on remote linux machines</a></li>
<li>Getting started with the Keras Sequential model</li>
<li>Getting started with the Keras functional API<br>25:</li>
<li><a href="https://www.bilibili.com/video/av9770302/index_3.html#page=4" target="_blank" rel="external">https://www.bilibili.com/video/av9770302/index_3.html#page=4</a></li>
<li>Cross Entropy<br>26:</li>
<li>The Unreasonable Effectiveness of Recurrent Neural Networks</li>
<li>The Unreasonable Effectiveness of Recurrent Neural Networks(OneNote)<br>27:</li>
<li>Sentence Generation using RNN</li>
<li>Python3: local, global, free variables(???)</li>
<li>SSH 退出后仍然保持程序继续运行<br>30:</li>
<li>Word2Vec on TensorFlow</li>
</ul>
<a id="more"></a>
<h2 id="卷积神经网络-in-Wiki"><a href="#卷积神经网络-in-Wiki" class="headerlink" title="卷积神经网络 in Wiki"></a>卷积神经网络 in Wiki</h2><h3 id="线性整流层"><a href="#线性整流层" class="headerlink" title="线性整流层"></a>线性整流层</h3><p><a href="https://www.wikiwand.com/zh-hans/%E5%8D%B7%E7%A7%AF%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C" target="_blank" rel="external">https://www.wikiwand.com/zh-hans/%E5%8D%B7%E7%A7%AF%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C</a><br>线性整流层（Rectified Linear Units layer, ReLU layer）使用线性整流（Rectified Linear Units, ReLU）作为这一层神经的激活函数（Activation function）。它可以增强判定函数和整个神经网络的非线性特性 <code>?</code>，而本身并不会改变卷积层。</p>
<h3 id="池化层"><a href="#池化层" class="headerlink" title="池化层"></a>池化层</h3><p>向下采样，非线性池化函数，而其中“最大池化（Max pooling）”是最为常见的。<br>压缩图像。<br>直觉上，这种机制能够有效地原因在于，在发现一个特征之后，它的精确位置远不及它和其他特征的相对位置的关系重要。</p>
<p>To understand an image its extremely important for a network to understand how the pixels are arranged.</p>
<p>We can take the input image, define a weight matrix and the input is convolved to extract specific features from the image without losing the information about its spatial arrangement.<br>Another great benefit this approach has is that it reduces the number of parameters from the image. As you saw above the convolved images had lesser pixels as compared to the original image. This dramatically reduces the number of parameters we need to train for the network.</p>
<h2 id="Architecture-of-Convolutional-Neural-Networks-CNNs-demystified"><a href="#Architecture-of-Convolutional-Neural-Networks-CNNs-demystified" class="headerlink" title="Architecture of Convolutional Neural Networks (CNNs) demystified"></a>Architecture of Convolutional Neural Networks (CNNs) demystified</h2><h3 id="Defining-a-Convolutional-Neural-Network"><a href="#Defining-a-Convolutional-Neural-Network" class="headerlink" title="Defining a Convolutional Neural Network"></a>Defining a Convolutional Neural Network</h3><p>We need three basic components to define a basic convolutional network.</p>
<ol>
<li>The convolutional layer</li>
<li>The Pooling layer[optional]</li>
<li>The output layer</li>
</ol>
<h4 id="The-Convolution-Layer"><a href="#The-Convolution-Layer" class="headerlink" title="The Convolution Layer"></a>The Convolution Layer</h4><p>The weight matrix behaves like a filter in an image extracting particular information from the original image matrix. A weight combination might be extracting edges, while another one might a particular color, while another one might just blur the unwanted noise.</p>
<p>The weights are learnt such that the loss function is minimized similar to an MLP. Therefore weights are learnt to extract features from the original image which help the network in correct prediction. When we have multiple convolutional layers, the initial layer extract more generic features, while as the network gets deeper, the features extracted by the weight matrices are more and more complex and more suited to the problem at hand.</p>
<h5 id="padding"><a href="#padding" class="headerlink" title="padding"></a>padding</h5><p>We can see how the initial shape of the image is retained after we padded the image with a zero. This is known as same padding since the output image has the same size as the input.</p>
<h5 id="activation-map"><a href="#activation-map" class="headerlink" title="activation map"></a>activation map</h5><p>This activation map is the output of the convolution layer.<br><img src="/2017/09/09/2017-09-01/markdown-img-paste-20170911100715418.png" alt="markdown-img-paste-20170911100715418.png" title=""></p>
<h2 id="CNN-各层效果"><a href="#CNN-各层效果" class="headerlink" title="CNN 各层效果"></a>CNN 各层效果</h2><h3 id="卷积"><a href="#卷积" class="headerlink" title="卷积"></a>卷积</h3><p>3x3 矩阵也叫“滤波器”、“核”或“特征探测器”，在原图上滑动滤波器、点乘矩阵所得的矩阵称为“卷积特征”、“激励映射”或“特征映射”。这里的重点就是，理解滤波器对于原输入图片来说，是个特征探测器。<br>对于同一张照片，不同的滤波器将会产生不同的特征映射。比如考虑下面这张输入图片：<br><img src="/2017/09/09/2017-09-01/markdown-img-paste-20170911111812281.png" alt="markdown-img-paste-20170911111812281.png" title=""><br>下表可见各种不同卷积核对于上图的效果。只需调整滤波器的数值，我们就可以执行诸如边缘检测、锐化、模糊等效果——这说明不同的滤波器会从图片中探测到不同的特征，比如边缘、曲线等。<br><img src="/2017/09/09/2017-09-01/markdown-img-paste-20170911111826987.png" alt="markdown-img-paste-20170911111826987.png" title=""></p>
<p>在实践当中，卷积神经网络在训练过程中学习滤波器的值，当然我们还是要在训练之前需要指定一些参数：滤波器的个数，滤波器尺寸、网络架构等等。滤波器越多，从图像中提取的特征就越多，模式识别能力就越强。</p>
<h3 id="非线性"><a href="#非线性" class="headerlink" title="非线性"></a>非线性</h3><p>ReLU 应用左图上，输出的新特征映射也叫“纠正”特征映射。（黑色被抹成了灰色）<br><img src="/2017/09/09/2017-09-01/markdown-img-paste-20170911112030158.png" alt="markdown-img-paste-20170911112030158.png" title=""></p>
<h3 id="池化"><a href="#池化" class="headerlink" title="池化"></a>池化</h3><p>空间池化（也叫亚采样或下采样）降低了每个特征映射的维度，但是保留了最重要的信息。空间池化可以有很多种形式：最大 (Max)，平均 (Average)，求和 (Sum) 等等。</p>
<p>使输入表征（特征维度）更小而易操作<br>减少网络中的参数与计算数量，从而遏制过拟合<br>增强网络对输入图像中的小变形、扭曲、平移的鲁棒性（输入里的微小扭曲不会改变池化输出——因为我们在局部邻域已经取了最大值 / 平均值）。<br>帮助我们获得不因尺寸而改变的等效图片表征。</p>
<h3 id="全连接层"><a href="#全连接层" class="headerlink" title="全连接层"></a>全连接层</h3><p>全连接层 (Fully Connected layer) 就是使用了 softmax 激励函数作为输出层的多层感知机 (Multi-Layer Perceptron)，其他很多分类器如支持向量机也使用了 softmax。“全连接”表示上一层的每一个神经元，都和下一层的每一个神经元是相互连接的。全连接层的目的是为了使用这些特征把输入图像基于训练数据集进行分类。</p>
<h2 id="tensorflow-一个最简单的神经网络"><a href="#tensorflow-一个最简单的神经网络" class="headerlink" title="tensorflow 一个最简单的神经网络"></a>tensorflow 一个最简单的神经网络</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> tensorflow <span class="keyword">as</span> tf</div><div class="line"><span class="keyword">from</span> tensorflow.examples.tutorials.mnist <span class="keyword">import</span> input_data</div><div class="line"></div><div class="line">mnist = input_data.read_data_sets(<span class="string">"MNIST_data/"</span>, one_hot=<span class="keyword">True</span>)</div><div class="line"></div><div class="line"></div><div class="line">W = tf.Variable(tf.zeros([<span class="number">784</span>, <span class="number">10</span>]))</div><div class="line">b = tf.Variable(tf.zeros([<span class="number">10</span>]))</div><div class="line"></div><div class="line">x = tf.placeholder(tf.float32, [<span class="keyword">None</span>, <span class="number">784</span>])</div><div class="line">y = tf.placeholder(tf.float32, [<span class="keyword">None</span>, <span class="number">10</span>])</div><div class="line">h = tf.nn.softmax(tf.matmul(x, W) + b)</div><div class="line">loss = tf.reduce_mean(-tf.reduce_sum(y * tf.log(h), reduction_indices=[<span class="number">1</span>]))</div><div class="line"></div><div class="line">train_step = tf.train.GradientDescentOptimizer(<span class="number">0.5</span>).minimize(loss)</div><div class="line"></div><div class="line">init = tf.global_variables_initializer()</div><div class="line">sess = tf.Session()</div><div class="line"></div><div class="line"><span class="keyword">with</span> sess.as_default():</div><div class="line">    sess.run(init)</div><div class="line"></div><div class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1000</span>):</div><div class="line">        batch_xs, batch_ys = mnist.train.next_batch(<span class="number">100</span>)</div><div class="line">        train_step.run(&#123;x: batch_xs, y: batch_ys&#125;)</div><div class="line"></div><div class="line">    correct_prediction = tf.equal(tf.argmax(h, <span class="number">1</span>), tf.argmax(y, <span class="number">1</span>))</div><div class="line">    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))</div><div class="line">    print(accuracy.eval(&#123;x: mnist.test.images, y: mnist.test.labels&#125;))</div></pre></td></tr></table></figure>
<h2 id="Introduction-of-Multilayer-Perceptron"><a href="#Introduction-of-Multilayer-Perceptron" class="headerlink" title="Introduction of Multilayer Perceptron"></a>Introduction of Multilayer Perceptron</h2><p>有了隐含层，神经网络就具有了一些特殊的属性，比如引入非线性的隐含层后，理论上只要隐含节点足够多，即便只有一个隐含层的神经网络也可以拟合任意函数。同时隐含层越多，越容易拟合复杂函数。有理论研究表明，为了拟合复杂函数需要的隐含节点的数目，基本上随着隐含层的数量增多呈指数下降趋势。也就是说层数越多，神经网络所需要的隐含节点可以越少。这也是深度学习的特点之一，层数越深，概念越抽象，需要背诵的知识点（神经网络隐含节点）就越少。 不过实际使用中，使用层数较深的神经网络会遇到许多困难，比如容易过拟合、参数难以 调试、梯度弥散，等等。对这些问题我们需要很多 Trick 来解决，在最近几年的研究中，越来越多的方法，比如 Dropout27、Adagrad28、ReLU29 等，逐渐帮助我们解决了一部分问题。</p>
<h2 id="自编码器中，令隐藏单元-i-得到最大激励的输入应由下面公式是计算的像素-xj-给出"><a href="#自编码器中，令隐藏单元-i-得到最大激励的输入应由下面公式是计算的像素-xj-给出" class="headerlink" title="自编码器中，令隐藏单元 i 得到最大激励的输入应由下面公式是计算的像素 xj 给出"></a>自编码器中，令隐藏单元 i 得到最大激励的输入应由下面公式是计算的像素 xj 给出</h2><img src="/2017/09/09/2017-09-01/markdown-img-paste-20170912152055485.png" alt="markdown-img-paste-20170912152055485.png" title="">
<h2 id="Numpy"><a href="#Numpy" class="headerlink" title="Numpy"></a>Numpy</h2><p>fromfunction, apply_along_axis, bincount, a.ravel()  # returns the array, flattened, View or Shallow Copy,</p>
<h3 id="View-or-Shallow-Copy"><a href="#View-or-Shallow-Copy" class="headerlink" title="View or Shallow Copy:"></a>View or Shallow Copy:</h3><p>The view method creates a new array object that looks at the same data.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">&gt;&gt;&gt; c = a.view()</div><div class="line">&gt;&gt;&gt; c is a</div><div class="line">False</div><div class="line">&gt;&gt;&gt; c.base is a                        # c is a view of the data owned by a</div><div class="line">True</div><div class="line">&gt;&gt;&gt; c.flags.owndata</div><div class="line">False</div></pre></td></tr></table></figure></p>
<h3 id="Slicing-an-array-returns-a-view-of-it"><a href="#Slicing-an-array-returns-a-view-of-it" class="headerlink" title="Slicing an array returns a view of it:"></a>Slicing an array returns a view of it:</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&gt;&gt;&gt; s = a[ : , 1:3]     # spaces added for clarity; could also be written &quot;s = a[:,1:3]&quot;</div><div class="line">&gt;&gt;&gt; s[:] = 10           # s[:] is a view of s. Note the difference between s=10 and s[:]=10</div><div class="line">&gt;&gt;&gt; a</div><div class="line">array([[   0,   10,   10,    3],</div><div class="line">       [1234,   10,   10,    7],</div><div class="line">       [   8,   10,   10,   11]])</div></pre></td></tr></table></figure>
<h3 id="Deep-Copy"><a href="#Deep-Copy" class="headerlink" title="Deep Copy"></a>Deep Copy</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">&gt;&gt;&gt; d = a.copy()                          # a new array object with new data is created</div><div class="line">&gt;&gt;&gt; d is a</div><div class="line">False</div><div class="line">&gt;&gt;&gt; d.base is a                           # d doesn&apos;t share anything with a</div><div class="line">False</div><div class="line">&gt;&gt;&gt; d[0,0] = 9999</div><div class="line">&gt;&gt;&gt; a</div><div class="line">array([[   0,   10,   10,    3],</div><div class="line">       [1234,   10,   10,    7],</div><div class="line">       [   8,   10,   10,   11]])</div></pre></td></tr></table></figure>
<h3 id="Functions-and-Methods-Overview-of-Numpy"><a href="#Functions-and-Methods-Overview-of-Numpy" class="headerlink" title="Functions and Methods Overview of Numpy"></a>Functions and Methods Overview of Numpy</h3><p><a href="https://docs.scipy.org/doc/numpy-dev/user/quickstart.html#functions-and-methods-overview" target="_blank" rel="external">https://docs.scipy.org/doc/numpy-dev/user/quickstart.html#functions-and-methods-overview</a></p>
<h3 id="Numpy-Fancy-indexing-and-index-tricks"><a href="#Numpy-Fancy-indexing-and-index-tricks" class="headerlink" title="Numpy: Fancy indexing and index tricks"></a>Numpy: Fancy indexing and index tricks</h3><p>Indexing with Arrays of Indices</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&gt;&gt;&gt; a = np.arange(12)**2                       # the first 12 square numbers</div><div class="line">&gt;&gt;&gt; i = np.array( [ 1,1,3,8,5 ] )              # an array of indices</div><div class="line">&gt;&gt;&gt; a[i]                                       # the elements of a at the positions i</div><div class="line">array([ 1,  1,  9, 64, 25])</div><div class="line">&gt;&gt;&gt;</div><div class="line">&gt;&gt;&gt; j = np.array( [ [ 3, 4], [ 9, 7 ] ] )      # a bidimensional array of indices</div><div class="line">&gt;&gt;&gt; a[j]                                       # the same shape as j</div><div class="line">array([[ 9, 16],</div><div class="line">       [81, 49]])</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">&gt;&gt;&gt; palette = np.array( [ [0,0,0],                # black</div><div class="line">...                       [255,0,0],              # red</div><div class="line">...                       [0,255,0],              # green</div><div class="line">...                       [0,0,255],              # blue</div><div class="line">...                       [255,255,255] ] )       # white</div><div class="line">&gt;&gt;&gt; image = np.array( [ [ 0, 1, 2, 0 ],           # each value corresponds to a color in the palette</div><div class="line">...                     [ 0, 3, 4, 0 ]  ] )</div><div class="line">&gt;&gt;&gt; palette[image]                            # the (2,4,3) color image</div><div class="line">array([[[  0,   0,   0],</div><div class="line">        [255,   0,   0],</div><div class="line">        [  0, 255,   0],</div><div class="line">        [  0,   0,   0]],</div><div class="line">       [[  0,   0,   0],</div><div class="line">        [  0,   0, 255],</div><div class="line">        [255, 255, 255],</div><div class="line">        [  0,   0,   0]]])</div></pre></td></tr></table></figure>
<h3 id="Numpy-Linear-Algebra"><a href="#Numpy-Linear-Algebra" class="headerlink" title="Numpy: Linear Algebra"></a>Numpy: Linear Algebra</h3><p><a href="https://docs.scipy.org/doc/numpy-dev/user/quickstart.html#linear-algebra" target="_blank" rel="external">https://docs.scipy.org/doc/numpy-dev/user/quickstart.html#linear-algebra</a></p>
<h3 id="“-Automatic-”-Reshaping"><a href="#“-Automatic-”-Reshaping" class="headerlink" title="“ Automatic ” Reshaping"></a>“ Automatic ” Reshaping</h3><p><a href="https://docs.scipy.org/doc/numpy-dev/user/quickstart.html#vector-stacking" target="_blank" rel="external">https://docs.scipy.org/doc/numpy-dev/user/quickstart.html#vector-stacking</a></p>
<p><a href="https://docs.scipy.org/doc/numpy-dev/user/numpy-for-matlab-users.html" target="_blank" rel="external">NumPy for Matlab users</a></p>
<h2 id="Numpy-Reference"><a href="#Numpy-Reference" class="headerlink" title="Numpy Reference"></a>Numpy Reference</h2><p><a href="https://docs.scipy.org/doc/numpy-dev/reference/index.html#reference" target="_blank" rel="external">https://docs.scipy.org/doc/numpy-dev/reference/index.html#reference</a></p>
<h3 id="Array-objects"><a href="#Array-objects" class="headerlink" title="Array objects"></a>Array objects</h3><ul>
<li>The N-dimensional array (ndarray)</li>
<li>Scalars</li>
<li>Data type objects (dtype)</li>
<li>Indexing</li>
<li>Iterating Over Arrays</li>
<li>Standard array subclasses</li>
<li>Masked arrays</li>
<li>The Array Interface</li>
<li>Datetimes and Timedeltas</li>
</ul>
<h3 id="Universal-functions-ufunc"><a href="#Universal-functions-ufunc" class="headerlink" title="Universal functions (ufunc)"></a>Universal functions (ufunc)</h3><ul>
<li>Broadcasting</li>
<li>Output type determination</li>
<li>Use of internal buffers</li>
<li>Error handling</li>
<li>Casting Rules</li>
<li>Overriding Ufunc behavior</li>
<li>ufunc</li>
<li>Available ufuncs</li>
</ul>
<h3 id="Routines"><a href="#Routines" class="headerlink" title="Routines"></a>Routines</h3><ul>
<li>Array creation routines</li>
<li>Array manipulation routines</li>
<li>Binary operations</li>
<li>String operations</li>
<li>C-Types Foreign Function Interface (numpy.ctypeslib)</li>
<li>Datetime Support Functions</li>
<li>Data type routines</li>
<li>Optionally Scipy-accelerated routines (numpy.dual)</li>
<li>Mathematical functions with automatic domain (numpy.emath)</li>
<li>Floating point error handling</li>
<li>Discrete Fourier Transform (numpy.fft)</li>
<li>Financial functions</li>
<li>Functional programming</li>
<li>NumPy-specific help functions</li>
<li>Indexing routines</li>
<li>Input and output</li>
<li>Linear algebra (numpy.linalg)</li>
<li>Logic functions</li>
<li>Masked array operations</li>
<li>Mathematical functions</li>
<li>Matrix library (numpy.matlib)</li>
<li>Miscellaneous routines</li>
<li>Padding Arrays</li>
<li>Polynomials</li>
<li>Random sampling (numpy.random)</li>
<li>Set routines</li>
<li>Sorting, searching, and counting</li>
<li>Statistics</li>
<li>Test Support (numpy.testing)</li>
<li>Window functions</li>
</ul>
<h3 id="Packaging-numpy-distutils"><a href="#Packaging-numpy-distutils" class="headerlink" title="Packaging (numpy.distutils)"></a>Packaging (numpy.distutils)</h3><ul>
<li>Modules in numpy.distutils</li>
<li>Building Installable C libraries</li>
<li>Conversion of .src files</li>
</ul>
<h2 id="local-global-and-free-variable"><a href="#local-global-and-free-variable" class="headerlink" title="local, global and free variable"></a>local, global and free variable</h2><p>local vs global<br>当你想在子代码块中对某个全局变量重新赋值时，实际上你只是定义了一个同名的本地变量，这并不会改变全局变量的值。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">&gt;&gt;&gt; global_var = &apos;global_val&apos;</div><div class="line">&gt;&gt;&gt; def showval():</div><div class="line">...     local_var = &apos;local_val&apos;</div><div class="line">...     print &quot;before defining inner func, showval.locals(): &quot;, locals()</div><div class="line">...     def innerFunc():</div><div class="line">...         print &quot;Inside innerFunc, local_var: &quot;, local_var</div><div class="line">...         print &quot;innerFunc.locals:&quot;, locals()</div><div class="line">...     print &quot;after defining inner func, showval.locals(): &quot;, locals()</div><div class="line">...     print &quot;showval.globals():&quot;, globals()</div><div class="line">...     return innerFunc</div><div class="line">...</div><div class="line">&gt;&gt;&gt; a_func = showval()</div><div class="line">before defining inner func, showval.locals():  &#123;&apos;local_var&apos;: &apos;local_val&apos;&#125;</div><div class="line">after defining inner func, showval.locals():  &#123;&apos;innerFunc&apos;: &lt;function innerFunc at 0x109caed70&gt;, &apos;local_var&apos;: &apos;local_val&apos;&#125;</div><div class="line">showval.globals(): &#123;&apos;__builtins__&apos;: &lt;module &apos;__builtin__&apos; (built-in)&gt;, &apos;global_var&apos;: &apos;global_val&apos;, &apos;__package__&apos;: None, &apos;__name__&apos;: &apos;__main__&apos;, &apos;__doc__&apos;: None, &apos;showval&apos;: &lt;function showval at 0x109cae938&gt;&#125;</div><div class="line">&gt;&gt;&gt;</div><div class="line">&gt;&gt;&gt; a_func</div><div class="line">&lt;function innerFunc at 0x109caed70&gt;</div><div class="line">&gt;&gt;&gt; a_func()</div><div class="line">Inside innerFunc, local_var:  local_val</div><div class="line">innerFunc.locals: &#123;&apos;local_var&apos;: &apos;local_val&apos;&#125;</div></pre></td></tr></table></figure></p>
<p>local_var 被 innerFunc 函数使用，但是并未在其中定义，所以对于 innerFunc 代码块来说，它就是自由变量。问题来了，自由变量为什么出现在<br>innerFunc.locals() 的输出结果中？这就需要看看<a href="https://docs.python.org/2/library/functions.html#locals" target="_blank" rel="external">locals()API</a> 文档了：<br>“””Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks.”””</p>
<h2 id="SSH-退出后仍然保持程序继续运行"><a href="#SSH-退出后仍然保持程序继续运行" class="headerlink" title="SSH 退出后仍然保持程序继续运行"></a>SSH 退出后仍然保持程序继续运行</h2><p><a href="https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/index.html" target="_blank" rel="external">https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/index.html</a></p>
<p>我们经常会碰到这样的问题，用 telnet/ssh 登录了远程的 Linux 服务器，运行了一些耗时较长的任务， 结果却由于网络的不稳定导致任务中途失败。如何让命令提交后不受本地关闭终端窗口 / 网络断开连接的干扰呢？下面举了一些例子， 您可以针对不同的场景选择不同的方式来处理这个问题。</p>
<h3 id="nohup-setsid-amp"><a href="#nohup-setsid-amp" class="headerlink" title="nohup/setsid/&amp;"></a>nohup/setsid/&amp;</h3><p>场景：<br>  如果只是临时有一个命令需要长时间运行，什么方法能最简便的保证它在后台稳定运行呢？<br>解决方法：<br>  我们知道，当用户注销（logout）或者网络断开时，终端会收到 HUP（hangup）信号从而关闭其所有子进程。因此，我们的解决办法就有两种途径：要么让进程忽略 HUP 信号，要么让进程运行在新的会话里从而成为不属于此终端的子进程。</p>
<h4 id="nohup"><a href="#nohup" class="headerlink" title="nohup"></a>nohup</h4><p>nohup 无疑是我们首先想到的办法。顾名思义，nohup 的用途就是让提交的命令忽略 hangup 信号。让我们先来看一下 nohup 的帮助信息：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">NOHUP(1)                        User Commands                        NOHUP(1)</div><div class="line"></div><div class="line">NAME</div><div class="line">       nohup - run a command immune to hangups, with output to a non-tty</div><div class="line"></div><div class="line">SYNOPSIS</div><div class="line">       nohup COMMAND [ARG]...</div><div class="line">       nohup OPTION</div><div class="line"></div><div class="line">DESCRIPTION</div><div class="line">       Run COMMAND, ignoring hangup signals.</div><div class="line"></div><div class="line">       --help display this help and exit</div><div class="line"></div><div class="line">       --version</div><div class="line">              output version information and exit</div></pre></td></tr></table></figure></p>
<p>可见，nohup 的使用是十分方便的，只需在要处理的命令前加上 nohup 即可，标准输出和标准错误缺省会被重定向到 nohup.out 文件中。一般我们可在结尾加上 “&amp;” 来将命令同时放入后台运行，也可用 <code>&gt;filename 2&gt;&amp;1</code> 来更改缺省的重定向文件名。</p>
<p>nohup 示例<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@pvcent107 ~]# nohup ping www.ibm.com &amp;</div><div class="line">[1] 3059</div><div class="line">nohup: appending output to `nohup.out&apos;</div><div class="line">[root@pvcent107 ~]# ps -ef |grep 3059</div><div class="line">root      3059   984  0 21:06 pts/3    00:00:00 ping www.ibm.com</div><div class="line">root      3067   984  0 21:06 pts/3    00:00:00 grep 3059</div><div class="line">[root@pvcent107 ~]#</div></pre></td></tr></table></figure></p>
<h4 id="setsid"><a href="#setsid" class="headerlink" title="setsid"></a>setsid</h4><p>nohup 无疑能通过忽略 HUP 信号来使我们的进程避免中途被中断，但如果我们换个角度思考，如果我们的进程不属于接受 HUP 信号的终端的子进程，那么自然也就不会受到 HUP 信号的影响了。setsid 就能帮助我们做到这一点。让我们先来看一下 setsid 的帮助信息：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">SETSID(8)                 Linux Programmer ’ s Manual                 SETSID(8)</div><div class="line"></div><div class="line">NAME</div><div class="line">       setsid - run a program in a new session</div><div class="line"></div><div class="line">SYNOPSIS</div><div class="line">       setsid program [ arg ... ]</div><div class="line"></div><div class="line">DESCRIPTION</div><div class="line">       setsid runs a program in a new session.</div></pre></td></tr></table></figure></p>
<p>可见 setsid 的使用也是非常方便的，也只需在要处理的命令前加上 setsid 即可。</p>
<p>setsid 示例<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@pvcent107 ~]# setsid ping www.ibm.com</div><div class="line">[root@pvcent107 ~]# ps -ef |grep www.ibm.com</div><div class="line">root     31094     1  0 07:28 ?        00:00:00 ping www.ibm.com</div><div class="line">root     31102 29217  0 07:29 pts/4    00:00:00 grep www.ibm.com</div><div class="line">[root@pvcent107 ~]#</div></pre></td></tr></table></figure></p>
<p>值得注意的是，上例中我们的进程 ID(PID) 为 31094，而它的父 ID（PPID）为 1（即为 init 进程 ID），并不是当前终端的进程 ID。请将此例与 nohup 例中的父 ID 做比较。</p>
<h4 id="amp"><a href="#amp" class="headerlink" title="&amp;"></a><code>&amp;</code></h4><p>这里还有一个关于 subshell 的小技巧。我们知道，将一个或多个命名包含在“ () ”中就能让这些命令在子 shell 中运行中，从而扩展出很多有趣的功能，我们现在要讨论的就是其中之一。<br>当我们将 “&amp;” 也放入“ () ”内之后，我们就会发现所提交的作业并不在作业列表中，也就是说，是无法通过 jobs 来查看的。让我们来看看为什么这样就能躲过 HUP 信号的影响吧。<br>……</p>
<h3 id="disown"><a href="#disown" class="headerlink" title="disown"></a>disown</h3><p>场景：<br>我们已经知道，如果事先在命令前加上 nohup 或者 setsid 就可以避免 HUP 信号的影响。但是如果我们未加任何处理就已经提交了命令，该如何补救才能让它避免 HUP 信号的影响呢？</p>
<p>解决方法：<br>这时想加 nohup 或者 setsid 已经为时已晚，只能通过作业调度和 disown 来解决这个问题了。让我们来看一下 disown 的帮助信息：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">disown [-ar] [-h] [jobspec ...]</div><div class="line">	Without options, each jobspec is  removed  from  the  table  of</div><div class="line">	active  jobs.   If  the -h option is given, each jobspec is not</div><div class="line">	removed from the table, but is marked so  that  SIGHUP  is  not</div><div class="line">	sent  to the job if the shell receives a SIGHUP.  If no jobspec</div><div class="line">	is present, and neither the -a nor the -r option  is  supplied,</div><div class="line">	the  current  job  is  used.  If no jobspec is supplied, the -a</div><div class="line">	option means to remove or mark all jobs; the -r option  without</div><div class="line">	a  jobspec  argument  restricts operation to running jobs.  The</div><div class="line">	return value is 0 unless a jobspec does  not  specify  a  valid</div><div class="line">	job.</div></pre></td></tr></table></figure></p>
<p>可以看出，我们可以用如下方式来达成我们的目的。</p>
<ul>
<li>用 disown -h jobspec 来使某个作业忽略 HUP 信号。</li>
<li>用 disown -ah 来使所有的作业都忽略 HUP 信号。</li>
<li>用 disown -rh 来使正在运行的作业忽略 HUP 信号。</li>
</ul>
<p>需要注意的是，当使用过 disown 之后，会将把目标作业从作业列表中移除，我们将不能再使用 jobs 来查看它，但是依然能够用 ps -ef 查找到它。</p>
<p>但是还有一个问题，这种方法的操作对象是作业，如果我们在运行命令时在结尾加了 “&amp;” 来使它成为一个作业并在后台运行，那么就万事大吉了，我们可以通过 jobs 命令来得到所有作业的列表。但是如果并没有把当前命令作为作业来运行，如何才能得到它的作业号呢？答案就是用 CTRL-z（按住 Ctrl 键的同时按住 z 键）了！<br>CTRL-z 的用途就是将当前进程挂起（Suspend），然后我们就可以用 jobs 命令来查询它的作业号，再用 bg jobspec 来将它放入后台并继续运行。需要注意的是，如果挂起会影响当前进程的运行结果，请慎用此方法。</p>
<p>灵活运用 CTRL-z<br>在我们的日常工作中，我们可以用 CTRL-z 来将当前进程挂起到后台暂停运行，执行一些别的操作，然后再用 fg 来将挂起的进程重新放回前台（也可用 bg 来将挂起的进程放在后台）继续运行。这样我们就可以在一个终端内灵活切换运行多个任务，这一点在调试代码时尤为有用。因为将代码编辑器挂起到后台再重新放回时，光标定位仍然停留在上次挂起时的位置，避免了重新定位的麻烦。</p>
<p>disown 示例 1（如果提交命令时已经用“ &amp; ”将命令放入后台运行，则可以直接使用“ disown ”）<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@pvcent107 build]# cp -r testLargeFile largeFile &amp;</div><div class="line">[1] 4825</div><div class="line">[root@pvcent107 build]# jobs</div><div class="line">[1]+  Running                 cp -i -r testLargeFile largeFile &amp;</div><div class="line">[root@pvcent107 build]# disown -h %1</div><div class="line">[root@pvcent107 build]# ps -ef |grep largeFile</div><div class="line">root      4825   968  1 09:46 pts/4    00:00:00 cp -i -r testLargeFile largeFile</div><div class="line">root      4853   968  0 09:46 pts/4    00:00:00 grep largeFile</div><div class="line">[root@pvcent107 build]# logout</div></pre></td></tr></table></figure></p>
<h3 id="screen"><a href="#screen" class="headerlink" title="screen"></a>screen</h3><p>场景：<br>我们已经知道了如何让进程免受 HUP 信号的影响，但是如果有大量这种命令需要在稳定的后台里运行，如何避免对每条命令都做这样的操作呢？</p>
<p>解决方法：<br>此时最方便的方法就是 screen 了。简单的说，screen 提供了 ANSI/VT100 的终端模拟器，使它能够在一个真实终端下运行多个全屏的伪终端。screen 的参数很多，具有很强大的功能，我们在此仅介绍其常用功能以及简要分析一下为什么使用 screen 能够避免 HUP 信号的影响。我们先看一下 screen 的帮助信息：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">SCREEN(1)                                                           SCREEN(1)</div><div class="line"></div><div class="line">NAME</div><div class="line">       screen - screen manager with VT100/ANSI terminal emulation</div><div class="line"></div><div class="line">SYNOPSIS</div><div class="line">       screen [ -options ] [ cmd [ args ] ]</div><div class="line">       screen -r [[pid.]tty[.host]]</div><div class="line">       screen -r sessionowner/[[pid.]tty[.host]]</div><div class="line"></div><div class="line">DESCRIPTION</div><div class="line">       Screen  is  a  full-screen  window manager that multiplexes a physical</div><div class="line">       terminal between several  processes  (typically  interactive  shells).</div><div class="line">       Each  virtual  terminal provides the functions of a DEC VT100 terminal</div><div class="line">       and, in addition, several control functions from the  ISO  6429  (ECMA</div><div class="line">       48,  ANSI  X3.64)  and ISO 2022 standards (e.g. insert/delete line and</div><div class="line">       support for multiple character sets).  There is a  scrollback  history</div><div class="line">       buffer  for  each virtual terminal and a copy-and-paste mechanism that</div><div class="line">       allows moving text regions between windows.</div></pre></td></tr></table></figure></p>
<p>使用 screen 很方便，有以下几个常用选项：<br>用 screen -dmS session name 来建立一个处于断开模式下的会话（并指定其会话名）。<br>用 screen -list 来列出所有会话。<br>用 screen -r session name 来重新连接指定会话。<br>用快捷键 CTRL-a d 来暂时断开当前会话。</p>
<p>screen 示例<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@pvcent107 ~]# screen -dmS Urumchi</div><div class="line">[root@pvcent107 ~]# screen -list</div><div class="line">There is a screen on:</div><div class="line">        12842.Urumchi   (Detached)</div><div class="line">1 Socket in /tmp/screens/S-root.</div><div class="line"></div><div class="line">[root@pvcent107 ~]# screen -r Urumchi</div><div class="line">[root@pvcent107 ~]# exit # 退出</div></pre></td></tr></table></figure></p>
<h4 id="1-未使用-screen-时新进程的进程树"><a href="#1-未使用-screen-时新进程的进程树" class="headerlink" title="1. 未使用 screen 时新进程的进程树"></a>1. 未使用 screen 时新进程的进程树</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@pvcent107 ~]# ping www.google.com &amp;</div><div class="line">[1] 9499</div><div class="line">[root@pvcent107 ~]# pstree -H 9499</div><div class="line">init ─┬─ Xvnc</div><div class="line">     ├─ acpid</div><div class="line">     ├─ atd</div><div class="line">     ├─ 2*[sendmail]</div><div class="line">     ├─ sshd ─┬─ sshd ─── bash ─── pstree</div><div class="line">     │      └─ sshd ─── bash ─── ping</div></pre></td></tr></table></figure>
<p>我们可以看出，未使用 screen 时我们所处的 bash 是 sshd 的子进程，当 ssh 断开连接时，HUP 信号自然会影响到它下面的所有子进程（包括我们新建立的 ping 进程）。</p>
<h4 id="2-使用了-screen-后新进程的进程树"><a href="#2-使用了-screen-后新进程的进程树" class="headerlink" title="2. 使用了 screen 后新进程的进程树"></a>2. 使用了 screen 后新进程的进程树</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@pvcent107 ~]# screen -r Urumchi</div><div class="line">[root@pvcent107 ~]# ping www.ibm.com &amp;</div><div class="line">[1] 9488</div><div class="line">[root@pvcent107 ~]# pstree -H 9488</div><div class="line">init ─┬─ Xvnc</div><div class="line">     ├─ acpid</div><div class="line">     ├─ atd</div><div class="line">     ├─ screen ─── bash ─── ping</div><div class="line">     ├─ 2*[sendmail]</div></pre></td></tr></table></figure>
<p>而使用了 screen 后就不同了，此时 bash 是 screen 的子进程，而 screen 是 init（PID 为 1）的子进程。那么当 ssh 断开连接时，HUP 信号自然不会影响到 screen 下面的子进程了。</p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>现在几种方法已经介绍完毕，我们可以根据不同的场景来选择不同的方案。nohup/setsid 无疑是临时需要时最方便的方法，disown 能帮助我们来事后补救当前已经在运行了的作业，而 screen 则是在大批量操作时不二的选择了。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/09/SVD/" rel="next" title="Singular Value Decomposition(SVD)">
                <i class="fa fa-chevron-left"></i> Singular Value Decomposition(SVD)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/09/UFLDL-Tutorial/" rel="prev" title="UFLDL Tutorial">
                UFLDL Tutorial <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/uploads/avatar.jpg"
               alt="东木金" />
          <p class="site-author-name" itemprop="name">东木金</p>
           
              <p class="site-description motion-element" itemprop="description">正在学习机器学习，希望能变得很强！</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">162</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">18</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">42</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/bdmk" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                    
                      GitHub
                    
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="mailto:catcherchan94@outlook.com" target="_blank" title="E-Mail">
                  
                    <i class="fa fa-fw fa-envelope"></i>
                  
                    
                      E-Mail
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Daily"><span class="nav-number">1.</span> <span class="nav-text">Daily</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#卷积神经网络-in-Wiki"><span class="nav-number">2.</span> <span class="nav-text">卷积神经网络 in Wiki</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#线性整流层"><span class="nav-number">2.1.</span> <span class="nav-text">线性整流层</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#池化层"><span class="nav-number">2.2.</span> <span class="nav-text">池化层</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Architecture-of-Convolutional-Neural-Networks-CNNs-demystified"><span class="nav-number">3.</span> <span class="nav-text">Architecture of Convolutional Neural Networks (CNNs) demystified</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Defining-a-Convolutional-Neural-Network"><span class="nav-number">3.1.</span> <span class="nav-text">Defining a Convolutional Neural Network</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#The-Convolution-Layer"><span class="nav-number">3.1.1.</span> <span class="nav-text">The Convolution Layer</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#padding"><span class="nav-number">3.1.1.1.</span> <span class="nav-text">padding</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#activation-map"><span class="nav-number">3.1.1.2.</span> <span class="nav-text">activation map</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#CNN-各层效果"><span class="nav-number">4.</span> <span class="nav-text">CNN 各层效果</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#卷积"><span class="nav-number">4.1.</span> <span class="nav-text">卷积</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#非线性"><span class="nav-number">4.2.</span> <span class="nav-text">非线性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#池化"><span class="nav-number">4.3.</span> <span class="nav-text">池化</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#全连接层"><span class="nav-number">4.4.</span> <span class="nav-text">全连接层</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#tensorflow-一个最简单的神经网络"><span class="nav-number">5.</span> <span class="nav-text">tensorflow 一个最简单的神经网络</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Introduction-of-Multilayer-Perceptron"><span class="nav-number">6.</span> <span class="nav-text">Introduction of Multilayer Perceptron</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#自编码器中，令隐藏单元-i-得到最大激励的输入应由下面公式是计算的像素-xj-给出"><span class="nav-number">7.</span> <span class="nav-text">自编码器中，令隐藏单元 i 得到最大激励的输入应由下面公式是计算的像素 xj 给出</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Numpy"><span class="nav-number">8.</span> <span class="nav-text">Numpy</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#View-or-Shallow-Copy"><span class="nav-number">8.1.</span> <span class="nav-text">View or Shallow Copy:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Slicing-an-array-returns-a-view-of-it"><span class="nav-number">8.2.</span> <span class="nav-text">Slicing an array returns a view of it:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Deep-Copy"><span class="nav-number">8.3.</span> <span class="nav-text">Deep Copy</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Functions-and-Methods-Overview-of-Numpy"><span class="nav-number">8.4.</span> <span class="nav-text">Functions and Methods Overview of Numpy</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Numpy-Fancy-indexing-and-index-tricks"><span class="nav-number">8.5.</span> <span class="nav-text">Numpy: Fancy indexing and index tricks</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Numpy-Linear-Algebra"><span class="nav-number">8.6.</span> <span class="nav-text">Numpy: Linear Algebra</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#“-Automatic-”-Reshaping"><span class="nav-number">8.7.</span> <span class="nav-text">“ Automatic ” Reshaping</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Numpy-Reference"><span class="nav-number">9.</span> <span class="nav-text">Numpy Reference</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Array-objects"><span class="nav-number">9.1.</span> <span class="nav-text">Array objects</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Universal-functions-ufunc"><span class="nav-number">9.2.</span> <span class="nav-text">Universal functions (ufunc)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Routines"><span class="nav-number">9.3.</span> <span class="nav-text">Routines</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Packaging-numpy-distutils"><span class="nav-number">9.4.</span> <span class="nav-text">Packaging (numpy.distutils)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#local-global-and-free-variable"><span class="nav-number">10.</span> <span class="nav-text">local, global and free variable</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SSH-退出后仍然保持程序继续运行"><span class="nav-number">11.</span> <span class="nav-text">SSH 退出后仍然保持程序继续运行</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#nohup-setsid-amp"><span class="nav-number">11.1.</span> <span class="nav-text">nohup/setsid/&</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#nohup"><span class="nav-number">11.1.1.</span> <span class="nav-text">nohup</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#setsid"><span class="nav-number">11.1.2.</span> <span class="nav-text">setsid</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#amp"><span class="nav-number">11.1.3.</span> <span class="nav-text">&</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#disown"><span class="nav-number">11.2.</span> <span class="nav-text">disown</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#screen"><span class="nav-number">11.3.</span> <span class="nav-text">screen</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-未使用-screen-时新进程的进程树"><span class="nav-number">11.3.1.</span> <span class="nav-text">1. 未使用 screen 时新进程的进程树</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-使用了-screen-后新进程的进程树"><span class="nav-number">11.3.2.</span> <span class="nav-text">2. 使用了 screen 后新进程的进程树</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#总结"><span class="nav-number">11.4.</span> <span class="nav-text">总结</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 - 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">东木金</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Gemini
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  






  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'manual') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

</body>
</html>
